local yanyu = fk.CreateSkill {
    name = "SP_heg__yanyu",
}

Fk:loadTranslationTable {
    ["SP_heg__yanyu"] = "燕语",
    [":SP_heg__yanyu"] = "每回合限一次，当你于回合外使用或打出一张牌后，你可以弃置一张和此牌类型不同的牌并获得之。",

    ["#SP_heg__yanyu-discard"] = "燕语：弃置一张与 %arg 类别不同的牌并获得之",

    ["$SP_heg__yanyu1"] = "家乡故音，佑君之体。",
    ["$SP_heg__yanyu2"] = "燕语呢喃，唤君之名。",
}

local yanyu_spec = {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(yanyu.name) and player.room.current ~= player and not player:isNude()
            and player:usedSkillTimes(yanyu.name, Player.HistoryTurn) == 0 and not data.card:isVirtual()
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local throw_type
        if data.card.type == Card.TypeBasic then
            throw_type = ".|.|.|.|.|trick,equip"
        else
            throw_type = ".|.|.|.|.|basic,equip"
        end
        local card = room:askToDiscard(target, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = yanyu.name,
            cancelable = true,
            pattern = throw_type,
            prompt = "#SP_heg__yanyu-discard:::" .. data.card:toLogString(),
            skip = true,
        })
        if #card > 0 then
            event:setCostData(self, { cards = card })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card = event:getCostData(self).cards[1]
        room:moveCardTo(card, Card.DiscardPile, player, fk.ReasonDiscard, yanyu.name, nil, true, player)
        if player.dead then return end
        room:obtainCard(player, data.card, true, fk.ReasonPrey, player, yanyu.name)
    end,
}

yanyu:addEffect(fk.CardUseFinished, yanyu_spec)
yanyu:addEffect(fk.CardRespondFinished, yanyu_spec)

return yanyu
